﻿using System;
using Audio;
using Controls;
using UnityEngine;
using Visual;

namespace Level
{
    public class GameOverState : MonoBehaviour, IState
    {
        public event Action GameOver;
        
        public float LiveTime { get; private set; }
        
        [SerializeField] private PlayerController playerController;
        [SerializeField] private CameraFollowPoint cameraFollowPoint;


        private void Update()
        {
            LiveTime += Time.deltaTime;
        }

        public IState Init(GameStateMachine stateMachine)
        {
            return this;
        }

        public void Enter()
        {
            AudioPlayer.Instance.SetVolume(0.3f);
            Time.timeScale = 0.1f;
            playerController.SwitchControl(PlayerController.ControlType.UI);
            cameraFollowPoint.enabled = false;
            cameraFollowPoint.transform.position = playerController.transform.position;
            
            enabled = false;
            GameOver?.Invoke();
        }

        public void Exit()
        {
            Time.timeScale = 1f;
        }
    }
}